package course;

public class Insurance {
    private static final int Basic_PREMIUM_RATE = 1000;
    private static final int[][] SETTING = {{0, 0, 0}, {28, 11, 50}, {18, 9, 100}, {10, 7, 150}, {8, 5, 200}, {15, 7, 250}};

    public static int[] calcSetting(int age) {
        if (age < 16 || age > 80) {
            return SETTING[0];
        } else if (age < 25) {
            return SETTING[1];
        } else if (age < 35) {
            return SETTING[2];
        } else if (age < 45) {
            return SETTING[3];
        } else if (age < 60) {
            return SETTING[4];
        } else {
            return SETTING[5];
        }
    }

    public int calcInsurance(int age, int score) {
        int insuranceMoney = -1;
        if (score > 0 && score < 13) {
            int[] setting = calcSetting(age);
            if (setting != SETTING[0]) {
                int safeDrivingDiscount = 0;
                int ageCoeffcient = setting[0];
                int scoreThreshold = setting[1];
                if (score > scoreThreshold) {
                    safeDrivingDiscount = setting[2];
                }
                insuranceMoney = (int) (Basic_PREMIUM_RATE / 10 * ageCoeffcient) - safeDrivingDiscount;
            }
        }
        return insuranceMoney;
    }
}
